﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Data;
using System.Data.Common;
using DataAccess;
/// <summary>
/// Summary description for RegisterCandidate
/// </summary>
public class RegisterCandidate
{
	public RegisterCandidate()
	{
		//
		// TODO: Add constructor logic here
		//
	}

    public bool Register(Candidate candidate)
    {
        InsertCandidate insert = new InsertCandidate();
        return insert.AddCandidate(candidate);
    }

    public static DataTable DisplayCandidate()
    {
        DataTable tblData = new DataTable();

        ConnectDAL conDal = new ConnectDAL();

        tblData = conDal.getData("SELECT ID,FullName,Username,Email,Mobile,Address FROM Candidate");

        return tblData;
    }

    public static bool DeleteCandidate(string id)
    {
        bool check;

        string sql = String.Format("DELETE FROM Candidate WHERE ID={0}",id);

        ConnectDAL conDal = new ConnectDAL();
        check = conDal.ExecuteQuery(sql);

        return check;
    }

    public static DataTable GetDetailCandidate(string id)
    {
        DataTable tblData = new DataTable();

        ConnectDAL conDal = new ConnectDAL();
        string sql = String.Format("SELECT * FROM Candidate WHERE ID={0}",id);

        tblData = conDal.getData(sql);

        return tblData;
    }

    public static bool UpdateCandidate(int id,string email,string cer,string exp,string full,string mobile,string add)
    {
        bool result = false;
        DbCommand cmd = GenericData.CreateCommand();
        string sql = String.Format("UPDATE Candidate SET Email='{0}',Certificate='{1}',Experience='{2}',FullName='{3}',Mobile='{4}',Address='{5}' WHERE ID={6}", email, cer, exp, full, mobile, add, id);
        cmd.CommandText = sql;
        if (GenericData.ExecuteNoneQuery(cmd) > 0)
            result = true;
        return result;
        //bool check;

        //string sql = String.Format("UPDATE Candidate SET Email='{0}',Certificate='{1}',Experience='{2}',FullName='{3}',Mobile='{4}',Address='{5}' WHERE ID={6}",email,cer,exp,full,mobile,add,id);

        //ConnectDAL conDal = new ConnectDAL();
        //check = conDal.ExecuteQuery(sql);

        //return check;
    }

    public static DataTable SearchCandidate(string fullname)
    {
        DataTable tblData = new DataTable();

        string sql = String.Format("SELECT ID,FullName,Username,Email,Mobile,Address FROM Candidate WHERE FullName LIKE '%{0}%'",fullname);
        ConnectDAL conDal = new ConnectDAL();
        tblData = conDal.getData(sql);

        return tblData;
    }
}